#include<iostream>
using namespace std;
const int N = 1e6 + 10;
int sum[N];
int flag[10] = { 1,0,0,0,1,0,1,0,2,1 };
int fun(int x)
{
	int ans = 0;
	while (x) {
		ans += flag[x % 10];
		x /= 10;
	}
	return ans;
}
int main()
{
	int t;
	cin >> t;
	//cout << fun(10) << endl;
	for (int i = 1; i <= 1e6; i++) {
		int ans = fun(i);
		sum[i] = sum[i - 1] + ans;
	}
	while (t--) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l - 1] << endl;
	}
	return 0;
}